
#import "FavoriteCell.h"
@interface FavoriteCell()
@property (strong, nonatomic) IBOutlet UIButton *selectBtn;
@property (strong, nonatomic) IBOutlet UIImageView *img;
@property (strong, nonatomic) IBOutlet UILabel *week;
@property (strong, nonatomic) IBOutlet UILabel *date;
@property (strong, nonatomic) IBOutlet UILabel *time;
@property (strong, nonatomic) IBOutlet UILabel *content;
@property (strong, nonatomic) IBOutlet UIButton *favoriteBtn;

@end

@implementation FavoriteCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
- (IBAction)actionForBtn:(UIButton *)sender {
    if (self.edit && sender.tag == 202) {
        return;
    }
    sender.selected = !sender.selected;
    if (self.block) {
        self.block(sender);
    }
}
- (void)setModel:(NoteModel*)model{
    _model = model;
    self.selectBtn.selected = model.select;
    if (model.data.count > 0) {
        self.img.image = [UIImage imageWithData:model.data[0]];
    }else{
        self.img.image = [UIImage imageWithData:model.sign.cover];
    }
    NSString * where = [NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"account"),bg_sqlValue(APP.user.account),bg_sqlKey(@"ID"),bg_sqlValue(model.sign.ID)];
    [SignModel bg_findAsync:nil where:where complete:^(NSArray * _Nullable array) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (array.count > 0) {
                SignModel *sign = [array lastObject];
                self.week.text = LS(sign.title);
            }
        });
    }];
    self.date.text = [NSDate transToDate:@"yyyy-MM-dd" :model.stamp];
    self.content.text = model.content;
    self.time.text = [NSDate transToDate:@"HH:mm" :model.stamp];
    self.favoriteBtn.selected = model.favorite;
}
@end
